/**
 * Created by yoyoyk on 2017/6/14.
 */
import {type} from './type';

function FloatNumber(number){}

FloatNumber.prototype["testNumber"] = testNumber;

FloatNumber.prototype["slice"] = sliceNumber;

FloatNumber.prototype["end"] = floatNumberTest;

function sliceNumber(num,maxLength){
    let p2 = this.testNumber(maxLength);

    if(this.testNumber(num) !== "number"){  throw Error("fly FloatNumber param1 is not a Number"); }

    if(p2 !== "number"){
            if(p2 === "string"){ p2 = parseInt(p2,10) }
            else {  throw Error("fly FloatNumber param2 is not a Number");  }
    }

    let str = num.toString(),hea = str.slice(0,str.indexOf(".")),end = this.end(num);

    if(p2 > end){ return; }

    return Number(hea + "." + end.slice(0,p2))
}

function floatNumberTest(num){
    let str = num.toString();

    return str.slice(str.indexOf(".")+1,str.length)
}

function testNumber(number){
    if(Number.isNaN(number)){ return "nan"; }else
        if(number == Infinity || number == -Infinity){ return "infinity"; }
        return type(number);
}

export {FloatNumber};